# 125. 验证回文串
# 如果在将所有大写字符转换为小写字符、并移除所有非字母数字字符之后，短语正着读和反着读都一样。则可以认为该短语是一个 回文串 。
# 字母和数字都属于字母数字字符。
# 给你一个字符串 s，如果它是 回文串 ，返回 true ；否则，返回 false 。
def isPalindrome(s):
    """
    :type s: str
    :rtype: bool
    """
    left_index, right_index = 0, len(s) - 1
    max_index = len(s) - 1
    re = True
    while left_index < right_index:
        while left_index < max_index and not s[left_index].isalnum():
            left_index += 1
        while right_index >= 0 and not s[right_index].isalnum():
            right_index -= 1
        if left_index < right_index and s[left_index].lower() != s[right_index].lower():
            re = False
            break
        else:
            left_index += 1
            right_index -= 1
    return re


def isPalindrome_short(s):
    """
    :type s: str
    :rtype: bool
    """
    s = [temp.lower() for temp in s if temp.isalnum()]
    return s == s[::-1]


s_1 = "A man, a plan, a canal: Panama"
result = isPalindrome_short(s_1)
print(f"result:{result}")

s_2 = "race a car"
result = isPalindrome_short(s_2)
print(f"result:{result}")

s_3 = "  "
result = isPalindrome_short(s_3)
print(f"result:{result}")

s_4 = "0p"
result = isPalindrome_short(s_4)
print(f"result:{result}")
